package com.gr.jron.model;

import javax.persistence.*;
import java.util.Date;

/**
 * Created by Jronrun.
 * User: jron
 * Date: 2007-7-19
 * Time: 21:10:22
 * It's jron's dream to cqiu
 */
@Entity
@Table(name = "JANSWER")
public class Answer extends BaseObject {

    private Long id;

    private Question question;
    private String title;
    private String content;
//    private Date create;
    private User user;
    private int version = 0;
    private Date answerTime;

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    public Long getId() {
        return id;
    }

    @ManyToOne(cascade = CascadeType.MERGE)
    @JoinColumn(name = "QUESTION_ID",nullable = false)
    public Question getQuestion() {
        return question;
    }

    public String getTitle() {
        return title;
    }

    @Column(length = 1000, nullable = true)
    public String getContent() {
        return content;
    }

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "USER_ID", nullable = false)
    public User getUser() {
        return user;
    }

    @Version
    public int getVersion() {
        return version;
    }

    @Column(updatable = false)
    public Date getAnswerTime() {
        return answerTime;
    }

    public void setAnswerTime(Date answerTime) {
        this.answerTime = answerTime;
    }

    public void setVersion(int version) {
        this.version = version;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public void setQuestion(Question question) {
        this.question = question;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Answer answer = (Answer) o;

        if (id != null ? !id.equals(answer.id) : answer.id != null) return false;

        return true;
    }

    public int hashCode() {
        return (id != null ? id.hashCode() : 0);
    }


    public String toString() {
        return "Answer{" +
                "title='" + title + '\'' +
                ", id=" + id +
                '}';
    }
}
